@echo off


set folder="D:\WWW\WWW\manage"
set output="D:\WWW\WWW\manage.zip"

@REM 压缩项目
@REM :: 删除现有的 zip 文件（如果存在）
@REM if exist "%output%" del "%output%"
@REM powershell -Command "Compress-Archive -Path '%folder%' -DestinationPath '%output%'"
@REM echo "Compression complete."



@REM 构建项目
set buildFolder="D:\WWW\WWW\docker-environment\manage\build"


@REM 复制项目
powershell -Command "Copy-Item -Path '%output%' -Destination '%buildFolder%\doc\manage.zip' -Force"

@REM 删除容器
powershell -Command "docker stop manage"
powershell -Command "docker rm manage"
powershell -Command "docker stop manage_cli"
powershell -Command "docker rm manage_cli"

@REM 删除镜像
powershell -Command "docker images"
powershell -Command "docker rmi 'manage:latest'"
powershell -Command "docker rmi 'sgsoft665/manage:latest'"


@REM 开始build
cd "%buildFolder%"
powershell -Command "docker-compose build"
echo "Docker Compose build complete."

@REM 获取镜像ID
set keyword="manage"
for /f "tokens=3" %%i in ('docker images ^| findstr /i "%keyword%"') do (
    set "imageId=%%i"
    goto :end
)
:end
echo image ID: %imageId% 


echo "Tag image..."
powershell -Command "docker tag %imageId% sgsoft665/manage:latest"
echo "Tag image complete."


@REM @REM 登录docker
@REM set username="qianhuankeji@gmail.com"
@REM set password="Fzqh@123456789"
@REM echo "Docker login..."
@REM powershell -Command "echo '%password%' | docker login --username %username% --password-stdin"
@REM echo "Docker login complete."

@REM echo "Pushing image to Docker Hub..."
@REM powershell -Command "docker push sgsoft665/manage:latest"
@REM echo "Pushing image to Docker Hub complete."

pause
